import EngineUtil from "./EngineUtil";
import LevelEditorDataMgr from "./LevelEditorDataMgr";
const { ccclass, property } = cc._decorator;

@ccclass
export default class EditorBottomItemCtrl extends cc.Component {
    @property(cc.Node)
    mapBg1 = null;

    row = null;
    col = null;
    isCanPlace = true;
    isPlace = false;
    isNeedPlace = false;
    relationPos = [];
    layerData = [];
    itemData = {};
    sitState = 1;

    onLoad() {
        this.mapBg1 = this.node.getChildByName("mapBg1");
    }

    start() {}

    initData(e) {
        if (e) {
            this.row = e.row;
            this.col = e.col;
        }
    }

    sitCanPlaceState(e) {
        this.sitState = e;
        this.isCanPlace = e === 1;
        this.mapBg1.color = this.getMapColor(e);
        this.updateMapData();
    }

    getMapColor(e) {
        let color = null;
        if (e === 1) {
            color = EngineUtil.getColor("#FFFFFF");
        } else if (e === 2) {
            color = EngineUtil.getColor("#141212");
        } else if (e === 3) {
            color = EngineUtil.getColor("#808080");
        }
        return color;
    }

    updateMapData() {
        LevelEditorDataMgr.updateMapData(this.row, this.col, this.sitState);
    }
}
